package com.sangu.dianxiu.utils;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.sangu.dianxiu.BaseApp;
import com.sangu.dianxiu.ICallBack;
import com.sangu.dianxiu.config.Constants;

import java.util.Map;

/**维修类别数据请求接口的实现类
 * Created by sg2 on 2016/1/4.
 */
public class RepairTypeManager {
    //使用volley框架进行数据请求
    public RequestQueue requestQueue= Volley.newRequestQueue(BaseApp.getInstance());
    private StringRequest request;
    private StringRequest getRequest(final Map<String, String> map,final ICallBack callBack,String url)
    {
        StringRequest stringRequest=new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                callBack.onSuccess(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                callBack.onError(error);
            }
        }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                return map;
            }
        };
        stringRequest.setShouldCache(true);
        stringRequest.setTag(RepairTypeManager.class);
        return stringRequest;
    }
    //获取维修类别的数据请求

    public void getRepairType(Map<String, String> map, ICallBack callBack) {
        request=getRequest(map,callBack, Constants.URL_GET_REPAIR_TYPE);
        requestQueue.add(request);
    }
    //获取维修项目的数据请求

    public void getRepairProject(Map<String, String> map, ICallBack callBack) {
        request=getRequest(map,callBack, Constants.URL_GET_REPAIR_PROJECT);
        requestQueue.add(request);
    }


    public void getRecommendTypeOrProject(Map<String, String> map, ICallBack callBack) {
        request=getRequest(map,callBack, Constants.URL_GET_COMMENT_TYPE_OR_PROJECT);
        requestQueue.add(request);
    }
}
